#include "sys.h"

SYS_PARAMS __xdata sysParams;
SYS_TIMER __xdata sysTimer;

const u8 sysParamsDefaultTab[PARAMS2MEMORY_SIZE] = {
    MODBUS_ADDRESS_DEFAULT,
    MODBUS_BAUDRATE_DEFAULT, 
    BACKLIGHT_LUMINANCE_LEVEL_DEFAULT, 
    RELAY_MODE_DEFAULT,
    TEMPERATURE_AIR_SET_DEFAULT,
    AIR_CONDITIONER_SPEED_SET_DEFAULT,
    AIR_CONDITIONER_MODE_SET_DEFAULT,
    AIR_CONDITIONER_MODE_SUPPORTED_DEFAULT,
    TEMPERATURE_FLOOR_SET_DEFAULT,
    FRESH_AIR_SPEED_SET_DEFAULT,
    IS_LOW_TEMPERATURE_PROTECTED_DEFAULT,
    IS_ECONOMIC_MODE_DEFAULT,
    IS_AIR_BLOWER_CONTROLLED_DEFAULT,
    IS_POWER_OFF_MEMORY_DEFAULT,
    BACKLASH_UPPER_LIMIT_DEFAULT,
    BACKLASH_LOWER_LIMIT_DEFAULT,
    TEMPERATURE_UPPER_LIMIT_DEFAULT,
    TEMPERATURE_LOWER_LIMIT_DEFAULT,
    TEMPERATURE_UNIT_DEFAULT,
    PRESENT_SYS_PAGE_DEFAULT,
    MACHINE_TYPE_SUPPORTED_DEFAULT,
    IS_PARAMS_SAVED_FLAG_LOW,
    IS_PARAMS_SAVED_FLAG_HIGH,
};

u8 __xdata sysParamsTab[PARAMS2MEMORY_SIZE];
u8 __xdata readParamsTab[PARAMS2MEMORY_SIZE];

void myMemcpy_byte(u8 *dest, u8 *src, u8 len)
{
    while(len--)
        *dest++ = *src++;
}

void sys_timer_init(void)
{
    TIM_InitTypeDef __xdata TIM_InitStructure;
    TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload;
    TIM_InitStructure.TIM_Priority = Priority_1;
    TIM_InitStructure.TIM_Interrupt = ENABLE;
    TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_12T;
    TIM_InitStructure.TIM_ClkOut = DISABLE;
    TIM_InitStructure.TIM_Value = 65535 - (MAIN_Fosc / 12 / 1000 / 1000 * SYS_TIMER_BASE);
    
    TIM_InitStructure.TIM_Run = ENABLE;

    Timer_Inilize(Timer0, &TIM_InitStructure);
}
void print(u16 value)
{
    u8 __xdata tempBuf[5];
    tempBuf[0] = value / 1000 + 0x30;
    tempBuf[1] = (value % 1000) / 100 + 0x30;
    tempBuf[2] = (value % 100) / 10 + 0x30;
    tempBuf[3] = (value % 10) + 0x30;
    tempBuf[4] = 0;
    PrintString1(tempBuf);
    PrintString1(" ");
}
void println(u16 value)
{
    u8 __xdata tempBuf[5];
    tempBuf[0] = value / 1000 + 0x30;
    tempBuf[1] = (value % 1000) / 100 + 0x30;
    tempBuf[2] = (value % 100) / 10 + 0x30;
    tempBuf[3] = (value % 10) + 0x30;
    tempBuf[4] = 0;
    PrintString1(tempBuf);
    PrintString1("\n\r");
}

void sys_params_DeInit(void)
{
    storage_write(MEMORY_ADDR_START, sysParamsDefaultTab, PARAMS2MEMORY_SIZE);
    sys_params_init();
}

void sys_params_init(void)
{  
    u8 __xdata tempBuf[2];
    storage_read(MEMORY_ADDR_START + PARAMS2MEMORY_SIZE - 2, tempBuf, 2);

    if(tempBuf[0] == IS_PARAMS_SAVED_FLAG_LOW && tempBuf[1] == IS_PARAMS_SAVED_FLAG_HIGH)
    {
        storage_read(MEMORY_ADDR_START, sysParamsTab, PARAMS2MEMORY_SIZE);
        PrintString1("read params successed!\n\r");   
    }
    else
    {
        sys_params_DeInit();
        myMemcpy_byte((u8 *)sysParamsTab, (u8 *)sysParamsDefaultTab, PARAMS2MEMORY_SIZE);
        PrintString1("deinit params!\n\r");   
    }
    sysParams.regs.isPowerOffMemory = sysParamsTab[12];

    if(sysParams.regs.isPowerOffMemory)
    {
        myMemcpy_byte((u8 *)readParamsTab, (u8 *)sysParamsTab, PARAMS2MEMORY_SIZE);
    }

    u8 len = 0;
    sysParams.commAddr                          = sysParamsTab[len++];
    sysParams.commBradrate                      = sysParamsTab[len++];
    sysParams.backligntLevel                    = sysParamsTab[len++];
    sysParams.relayMode                         = sysParamsTab[len++];
    
    sysParams.regs.temperatureAirSet            = sysParamsTab[len++];
    sysParams.regs.airConditionerSpeedSet       = sysParamsTab[len++];
    sysParams.regs.airConditionerMode           = sysParamsTab[len++]; 
    sysParams.regs.airConditionerModeSupport    = sysParamsTab[len++];
    
    sysParams.regs.temperatureFloorSet          = sysParamsTab[len++];
    
    sysParams.regs.freshAirSpeedSet             = sysParamsTab[len++];

    sysParams.regs.isLowTemperatureProtected    = sysParamsTab[len++];
    sysParams.regs.isEconomicMode               = sysParamsTab[len++];
    sysParams.regs.isAirBlowerControlled        = sysParamsTab[len++];
    sysParams.regs.isPowerOffMemory             = sysParamsTab[len++];
    sysParams.regs.backlashUpperLimit           = sysParamsTab[len++];
    sysParams.regs.backlashLowerLimit           = sysParamsTab[len++];
    sysParams.regs.temperatureUpperLimit        = sysParamsTab[len++];
    sysParams.regs.temperatureLowerLimit        = sysParamsTab[len++];
    sysParams.regs.temperatureUnit              = sysParamsTab[len++];
    sysParams.regs.sysPage                      = sysParamsTab[len++];
    sysParams.regs.machineTypeSupported         = sysParamsTab[len++];
    sysParams.regs.temperatureSmp = 25;
    sysParams.presentPage = sysParams.regs.sysPage;
}

void sys_params_saved(void)
{
    u8 __xdata isSaved = 0;
    static u8 __xdata prePowerStatus;
    if(sysParams.regs.isPowerOffMemory)
    {
        u8 __xdata len = 0;
        sysParamsTab[len++] = sysParams.commAddr;
        sysParamsTab[len++] = sysParams.commBradrate;
        sysParamsTab[len++] = sysParams.backligntLevel;
        sysParamsTab[len++] = sysParams.relayMode;
        sysParamsTab[len++] = sysParams.regs.temperatureAirSet;
        sysParamsTab[len++] = sysParams.regs.airConditionerSpeedSet;
        sysParamsTab[len++] = sysParams.regs.airConditionerMode;
        sysParamsTab[len++] = sysParams.regs.airConditionerModeSupport;
        sysParamsTab[len++] = sysParams.regs.temperatureFloorSet;
        sysParamsTab[len++] = sysParams.regs.freshAirSpeedSet;
        sysParamsTab[len++] = sysParams.regs.isLowTemperatureProtected;
        sysParamsTab[len++] = sysParams.regs.isEconomicMode;
        sysParamsTab[len++] = sysParams.regs.isAirBlowerControlled;
        sysParamsTab[len++] = sysParams.regs.isPowerOffMemory;
        sysParamsTab[len++] = sysParams.regs.backlashUpperLimit;
        sysParamsTab[len++] = sysParams.regs.backlashLowerLimit;
        sysParamsTab[len++] = sysParams.regs.temperatureUpperLimit;
        sysParamsTab[len++] = sysParams.regs.temperatureLowerLimit;
        sysParamsTab[len++] = sysParams.regs.temperatureUnit;
        sysParamsTab[len++] = sysParams.regs.sysPage;
        sysParamsTab[len++] = sysParams.regs.machineTypeSupported;
        sysParamsTab[len++] = IS_PARAMS_SAVED_FLAG_LOW;
        sysParamsTab[len++] = IS_PARAMS_SAVED_FLAG_HIGH;
        
        for(u8 __xdata i = 0; i < PARAMS2MEMORY_SIZE; i++)
        {
            /* 系统运行时间改变不参与判断 */
            if(i != 21)
            {
                if(readParamsTab[i] != sysParamsTab[i])
                {
                    if(sysParams.isSaving)
                    {
                        sysParams.isSaving = 0;

                        storage_write(MEMORY_ADDR_START, sysParamsTab, PARAMS2MEMORY_SIZE);
                        myMemcpy_byte(readParamsTab, sysParamsTab, PARAMS2MEMORY_SIZE);
                        PrintString1("saved");
                        isSaved = 1;
                        prePowerStatus = sysParams.regs.powerStatus;
                    }
                    break;
                }
            }
        }

        if(isSaved == 0)
        {
            if(prePowerStatus != sysParams.regs.powerStatus)
            {
                prePowerStatus = sysParams.regs.powerStatus;
                storage_write(MEMORY_ADDR_START, sysParamsTab, PARAMS2MEMORY_SIZE);
                myMemcpy_byte(readParamsTab, sysParamsTab, PARAMS2MEMORY_SIZE);
                PrintString1("saved");
            }
        }
    }
}

void sys_page_airConditioner(void)
{
    /* 通风模式下 */
    if(sysParams.regs.airConditionerMode == AIR_CONDITIONER_MODE_AIR_CIRCULATION)
    {
        /* 空调通风模式下，无自动风速 */
        if(sysParams.regs.airConditionerSpeedSet == SET_WIND_SPEED_AUTO)
        {
            sysParams.regs.airConditionerSpeedSet = SET_WIND_SPEED_LOW;
        }
    }

    /* 节能模式下 */
    if(sysParams.regs.isEconomicMode)
    {
        if(sysParams.regs.airConditionerMode == AIR_CONDITIONER_MODE_COOLING)
        {
            if(sysParams.regs.temperatureAirSet < 26)
            {
                sysParams.regs.temperatureAirSet = 26;
            }
        }
        else if(sysParams.regs.airConditionerMode == AIR_CONDITIONER_MODE_HEATING)
        {
            if(sysParams.regs.temperatureAirSet > 20)
            {
                sysParams.regs.temperatureAirSet = 20;
            }
        }
            
    }
    
    /* 检测到power键短按，切换空调电源状态 */
    if(sysParams.btn.btnPower == PRESSED)
    {
        sysParams.btn.btnPower = RELEASED;
        /* 切换空调电源状态 */
        sysParams.regs.powerStatus ^= POWER_AIR_CONDITIONER_MASK;
        // /* 空调电源关闭，但地暖或者新风还在工作，则自动切换界面 */
        // if((sysParams.regs.powerStatus & POWER_AIR_CONDITIONER_MASK) == 0)
        // {
        //     if(sysParams.regs.powerStatus & POWER_FLOOR_HEATING_MASK)
        //     {
        //         sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
        //         sysParams.presentPage = sysParams.regs.sysPage;
        //     }
        //     else if(sysParams.regs.powerStatus & POWER_FRESH_AIR_MASK)
        //     {
        //         sysParams.regs.sysPage = PAGE_FRESH_AIR;
        //         sysParams.presentPage = sysParams.regs.sysPage;
        //     }
        // }
    }
    /* 空调电源为开机状态下，以下按键生效 */
    if(sysParams.regs.powerStatus & POWER_AIR_CONDITIONER_MASK)
    {
        /* 检测到mode键短按，切换空调模式  */
        if(sysParams.btn.btnMode == PRESSED)
        {
            sysParams.btn.btnMode = RELEASED;
            switch(sysParams.regs.airConditionerMode)
            {
                case AIR_CONDITIONER_MODE_COOLING:
                    /* 有制热模式 */
                    if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_HEATING_MASK)
                    {
                        sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_HEATING;
                    }
                    /* 无制热模式 */
                    else
                    {
                        /* 有通风模式 */
                        if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_AIR_CIRCULATION_MASK)
                        {
                            sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_AIR_CIRCULATION;
                        }
                        /* 无通风模式 */
                        else
                        {
                            /* 有除湿模式 */
                            if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_DEHUMIDIFICATION_MASK)
                            {
                                sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_DEHUMIDIFICATION;
                            }
                            else
                            {
                                //不动作
                            }
                        }
                    }
                    break;
                case AIR_CONDITIONER_MODE_HEATING:
                    /* 有通风模式 */
                    if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_AIR_CIRCULATION_MASK)
                    {
                        sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_AIR_CIRCULATION;
                    }
                    /* 无通风模式 */
                    else
                    {
                        /* 有除湿模式 */
                        if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_DEHUMIDIFICATION_MASK)
                        {
                            sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_DEHUMIDIFICATION;
                        }
                        else
                        {
                            /* 有制冷模式 */
                            if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_COOLING_MASK)
                            {
                                sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_COOLING;
                            }
                            /* 无制冷模式 */
                            else
                            {
                                //不动作
                            }
                        }
                    }
                    break;
                case AIR_CONDITIONER_MODE_AIR_CIRCULATION:
                    /* 有除湿模式 */
                    if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_DEHUMIDIFICATION_MASK)
                    {
                        sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_DEHUMIDIFICATION;
                    }
                    else
                    {
                        /* 有制冷模式 */
                        if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_COOLING_MASK)
                        {
                            sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_COOLING;
                        }
                        /* 无制冷模式 */
                        else
                        {
                            /* 有制热模式 */
                            if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_HEATING_MASK)
                            {
                                sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_HEATING;
                            }
                            else
                            {
                                //不动作
                            }
                        }
                    }
                    break;
                case AIR_CONDITIONER_MODE_DEHUMIDIFICATION:
                    /* 有制冷模式 */
                    if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_COOLING_MASK)
                    {
                        sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_COOLING;
                    }
                    /* 无制冷模式 */
                    else
                    {
                        /* 有制热模式 */
                        if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_HEATING_MASK)
                        {
                            sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_HEATING;
                        }
                        else
                        {
                            /* 有通风模式 */
                            if(sysParams.regs.airConditionerModeSupport & AIR_CONDITIONER_MODE_SUPPORTED_AIR_CIRCULATION_MASK)
                            {
                                sysParams.regs.airConditionerMode = AIR_CONDITIONER_MODE_AIR_CIRCULATION;
                            }
                            else
                            {
                                //不动作
                            }
                        }
                    }
                    break;
            }
        }
        /* 检测到wind键短按，切换风速模式 */
        else if(sysParams.btn.btnWindSpeed == PRESSED)
        {
            sysParams.btn.btnWindSpeed = RELEASED;
            switch(sysParams.regs.airConditionerMode)
            {
                case AIR_CONDITIONER_MODE_COOLING:
                case AIR_CONDITIONER_MODE_HEATING:
                    if(sysParams.regs.airConditionerSpeedSet < SET_WIND_SPEED_HIGH)
                    {
                        sysParams.regs.airConditionerSpeedSet++;
                    }
                    else
                    {
                        sysParams.regs.airConditionerSpeedSet = SET_WIND_SPEED_AUTO;
                    }
                    break;
                case AIR_CONDITIONER_MODE_AIR_CIRCULATION:
                    if(sysParams.regs.airConditionerSpeedSet < SET_WIND_SPEED_HIGH)
                    {
                        sysParams.regs.airConditionerSpeedSet++;
                    }
                    else
                    {
                        sysParams.regs.airConditionerSpeedSet = SET_WIND_SPEED_LOW;
                    }
                    break;
                case AIR_CONDITIONER_MODE_DEHUMIDIFICATION:
                    /* 除湿模式下风速不可调整 */
                    break;
            }
            
        }
        /* 检测到down键短按，降低空调设定温度 */
        else if(sysParams.btn.btnDown == PRESSED)
        {
            sysParams.btn.btnDown = RELEASED;
            switch(sysParams.regs.airConditionerMode)
            {
                case AIR_CONDITIONER_MODE_COOLING:
                    /* 节能模式下 */
                    if(sysParams.regs.isEconomicMode)
                    {
                        if(sysParams.regs.temperatureAirSet > 26)
                        {
                            sysParams.regs.temperatureAirSet--;
                        }
                    }
                    /* 正常模式下 */
                    else
                    {
                        if(sysParams.regs.temperatureAirSet > sysParams.regs.temperatureLowerLimit)
                        {
                            sysParams.regs.temperatureAirSet--;
                        }
                    }
                    break;
                case AIR_CONDITIONER_MODE_HEATING:
                    if(sysParams.regs.temperatureAirSet > sysParams.regs.temperatureLowerLimit)
                    {
                        sysParams.regs.temperatureAirSet--;
                    }
                    break;
                case AIR_CONDITIONER_MODE_AIR_CIRCULATION:
                    /* 除湿模式下温度不可调整 */
                    break;
                case AIR_CONDITIONER_MODE_DEHUMIDIFICATION:
                    /* 除湿模式下温度不可调整 */
                    break;
            }
            
        }
        /* 检测到up键短按，升高空调设定温度 */
        else if(sysParams.btn.btnUp == PRESSED)
        {
            sysParams.btn.btnUp = RELEASED;
            switch(sysParams.regs.airConditionerMode)
            {
                case AIR_CONDITIONER_MODE_COOLING:
                    if(sysParams.regs.temperatureAirSet < sysParams.regs.temperatureUpperLimit)
                    {
                        sysParams.regs.temperatureAirSet++;
                    }
                    break;
                case AIR_CONDITIONER_MODE_HEATING:
                    /* 节能模式下 */
                    if(sysParams.regs.isEconomicMode)
                    {
                        if(sysParams.regs.temperatureAirSet < 20)
                        {
                            sysParams.regs.temperatureAirSet++;
                        }
                    }
                    /* 正常模式下 */
                    else
                    {
                        if(sysParams.regs.temperatureAirSet < sysParams.regs.temperatureUpperLimit)
                        {
                            sysParams.regs.temperatureAirSet++;
                        }
                    }
                    break;
                case AIR_CONDITIONER_MODE_AIR_CIRCULATION:
                    /* 除湿模式下温度不可调整 */
                    break;
                case AIR_CONDITIONER_MODE_DEHUMIDIFICATION:
                    /* 除湿模式下温度不可调整 */
                    break;
            }
            
        }
    }
    /* 空调电源为关机状态时，以下按键无效 */
    else
    {
        if(sysParams.btn.btnMode == PRESSED)
            sysParams.btn.btnMode = RELEASED;
        if(sysParams.btn.btnWindSpeed == PRESSED)
            sysParams.btn.btnWindSpeed = RELEASED;
        if(sysParams.btn.btnDown == PRESSED)
            sysParams.btn.btnDown = RELEASED;
        if(sysParams.btn.btnUp == PRESSED)
            sysParams.btn.btnUp = RELEASED;
    }
}

void sys_page_floorHeating(void)
{
    /* 检测到power键短按，切换地暖电源状态 */
    if(sysParams.btn.btnPower == PRESSED)
    {
        sysParams.btn.btnPower = RELEASED;
        /* 切换地暖电源状态 */
        sysParams.regs.powerStatus ^= POWER_FLOOR_HEATING_MASK;
        /* 地暖电源关闭，但空调或者新风还在工作，则自动切换界面 */
        // if((sysParams.regs.powerStatus & POWER_FLOOR_HEATING_MASK) == 0)
        // {
        //     if(sysParams.regs.powerStatus & POWER_AIR_CONDITIONER_MASK)
        //     {
        //         sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
        //         sysParams.presentPage = sysParams.regs.sysPage;
        //     }
        //     else if(sysParams.regs.powerStatus & POWER_FRESH_AIR_MASK)
        //     {
        //         sysParams.regs.sysPage = PAGE_FRESH_AIR;
        //         sysParams.presentPage = sysParams.regs.sysPage;
        //     }
        // }
    }
    /* 地暖电源为开机状态下，以下按键生效 */
    if(sysParams.regs.powerStatus & POWER_FLOOR_HEATING_MASK)
    {
        /* 检测到mode键短按，地暖模式下无需理会 */
        if(sysParams.btn.btnMode == PRESSED)
        {
            sysParams.btn.btnMode = RELEASED;
            /* 地暖无模式选项 */
        }
        /* 检测到wind键短按，地暖模式下无需理会 */
        else if(sysParams.btn.btnWindSpeed == PRESSED)
        {
            sysParams.btn.btnWindSpeed = RELEASED;
            /* 地暖无风速选项 */
        }
        /* 检测到down键短按，降低地暖设定温度 */
        else if(sysParams.btn.btnDown == PRESSED)
        {
            sysParams.btn.btnDown = RELEASED;
            if(sysParams.regs.temperatureFloorSet > sysParams.regs.temperatureLowerLimit)
            {
                sysParams.regs.temperatureFloorSet--;
            }
        }
        /* 检测到up键短按，升高地暖设定温度 */
        else if(sysParams.btn.btnUp == PRESSED)
        {
            sysParams.btn.btnUp = RELEASED;
            if(sysParams.regs.temperatureFloorSet < sysParams.regs.temperatureUpperLimit)
            {
                sysParams.regs.temperatureFloorSet++;
            }
        }
    }
    /* 地暖电源为关机状态时，以下按键无效 */
    else
    {
        if(sysParams.btn.btnMode == PRESSED)
            sysParams.btn.btnMode = RELEASED;
        if(sysParams.btn.btnWindSpeed == PRESSED)
            sysParams.btn.btnWindSpeed = RELEASED;
        if(sysParams.btn.btnDown == PRESSED)
            sysParams.btn.btnDown = RELEASED;
        if(sysParams.btn.btnUp == PRESSED)
            sysParams.btn.btnUp = RELEASED;
    }
}

void sys_page_fleshAir(void)
{
    /* 检测到power键短按，切换新风电源状态 */
    if(sysParams.btn.btnPower == PRESSED)
    {
        sysParams.btn.btnPower  = RELEASED;
        /* 切换新风电源状态 */
        sysParams.regs.powerStatus ^= POWER_FRESH_AIR_MASK;
        /* 地暖电源关闭，但空调或者新风还在工作，则自动切换界面 */
        // if((sysParams.regs.powerStatus & POWER_FRESH_AIR_MASK) == 0)
        // {
        //     if(sysParams.regs.powerStatus & POWER_AIR_CONDITIONER_MASK)
        //     {
        //         sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
        //         sysParams.presentPage = sysParams.regs.sysPage;
        //     }
        //     else if(sysParams.regs.powerStatus & POWER_FLOOR_HEATING_MASK)
        //     {
        //         sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
        //         sysParams.presentPage = sysParams.regs.sysPage;
        //     }
        // }
    }
    /* 新风电源为开机状态下，以下按键生效 */
    if(sysParams.regs.powerStatus & POWER_FRESH_AIR_MASK)
    {
        /* 检测到mode键短按，新风模式下无需理会 */
        if(sysParams.btn.btnMode == PRESSED)
        {
            sysParams.btn.btnMode = RELEASED;
            /* 新风无模式选项 */
        }
        /* 检测到wind键短按，调整风机风速 */
        else if(sysParams.btn.btnWindSpeed == PRESSED)
        {
            sysParams.btn.btnWindSpeed = RELEASED;
            if(sysParams.regs.freshAirSpeedSet < SET_WIND_SPEED_HIGH)
            {
                sysParams.regs.freshAirSpeedSet++;
            }
            else
            {
                sysParams.regs.freshAirSpeedSet = SET_WIND_SPEED_LOW;
            }
        }
        /* 检测到down键短按，新风模式下无需理会 */
        else if(sysParams.btn.btnDown == PRESSED)
        {
            sysParams.btn.btnDown = RELEASED;
            /* 新风无下调选项 */
        }
        /* 检测到up键短按，新风模式下无需理会 */
        else if(sysParams.btn.btnUp == PRESSED)
        {
            sysParams.btn.btnUp = RELEASED;
            /* 新风无上调选项 */
        }
    }
    /* 新风电源为关机状态时，以下按键无效 */
    else
    {
        if(sysParams.btn.btnMode == PRESSED)
            sysParams.btn.btnMode = RELEASED;
        if(sysParams.btn.btnWindSpeed == PRESSED)
            sysParams.btn.btnWindSpeed = RELEASED;
        if(sysParams.btn.btnDown == PRESSED)
            sysParams.btn.btnDown = RELEASED;
        if(sysParams.btn.btnUp == PRESSED)
            sysParams.btn.btnUp = RELEASED;
    }
}

void sys_page_engineer(u8 *isSelected)
{
    /* 高级菜单切换至工程师菜单 */
    if(sysParams.advancedMenu > ENGINEER_MENU_COMMUNICATION_ADDR)    
    {
        sysParams.advancedMenu = ENGINEER_MENU_TEMPERATURE_CALIBRATION;
    }
    else if(sysParams.advancedMenu < ENGINEER_MENU_TEMPERATURE_CALIBRATION)
    {
        sysParams.advancedMenu = ENGINEER_MENU_TEMPERATURE_CALIBRATION;
    }
    /* 检测到power键按下，返回系统界面 */
    if(sysParams.btn.btnPower == PRESSED)
    {
        sysParams.btn.btnPower = RELEASED;
        sysParams.presentPage = sysParams.regs.sysPage;
    }
    /* 检测到mode键按下，切换选中状态 */
    if(sysParams.btn.btnMode == PRESSED)
    {
        sysParams.btn.btnMode = RELEASED;
        /*切换选中状态*/
        *isSelected ^= 0x01;
        /* 选中参数，开始闪烁*/
        if(*isSelected)
            sysParams.isDisplayFlicker = 0x11;
        else
            sysParams.isDisplayFlicker = 0;
    }
    /* 检测到wind键按下，工程师模式无需理会 */
    if(sysParams.btn.btnWindSpeed == PRESSED)
    {
        sysParams.btn.btnWindSpeed = RELEASED;
        /* 工程师模式无风速选项 */
    }
    /* 检测到down键按下，切换菜单或调整参数 */
    if(sysParams.btn.btnDown == PRESSED)
    {
        sysParams.btn.btnDown = RELEASED;
        /* 未选中要修改的参数 */
        if((*isSelected & 0x01) == 0)   
        {
            /* 切换菜单 */
            if(sysParams.advancedMenu > ENGINEER_MENU_TEMPERATURE_CALIBRATION)
            {
                sysParams.advancedMenu--;
            }
        }
        /* 选中要修改的参数，进行参数调整 */
        else          
        {
            /* 调整后参数先显示，后闪烁 */
            sysParams.isDisplayFlicker = 0x11;    

            switch(sysParams.advancedMenu)
            {
                /* 温度校准 */
                case ENGINEER_MENU_TEMPERATURE_CALIBRATION: 
                    if(sysParams.regs.temperatureCalibration > -8)
                    {
                        sysParams.regs.temperatureCalibration--;
                    }
                break;
                /* 节能开关 */
                case ENGINEER_MENU_MODE_ECONOMIC:           
                    sysParams.regs.isEconomicMode = 0;
                break;
                /* 风机控制 */
                case ENGINEER_MENU_AIR_BLOWER_CONTROLLED:   
                    sysParams.regs.isAirBlowerControlled = 0;
                break;
                /* 低温保护 */
                case ENGINEER_MENU_LOW_TEMPERATURE_PROTECTED: 
                    sysParams.regs.isLowTemperatureProtected = 0;
                break;
                /* 断电记忆功能 */
                case ENGINEER_MENU_POWER_OFF_MEMORY:        
                    sysParams.regs.isPowerOffMemory = 0;
                break;
                /* 回差上限 */
                case ENGINEER_MENU_BACKLASH_UPPER_LIMIT: 
                    if(sysParams.regs.backlashUpperLimit > 0)
                        sysParams.regs.backlashUpperLimit--;
                break;
                /* 回差上限 */
                case ENGINEER_MENU_BACKLASH_LOWER_LIMIT: 
                    if(sysParams.regs.backlashLowerLimit > -6)
                        sysParams.regs.backlashLowerLimit--;
                break;
                /* 温度上限 */
                case ENGINEER_MENU_TEMPERATURE_UPPER_LIMIT: 
                    if(sysParams.regs.temperatureUpperLimit > 5)
                        sysParams.regs.temperatureUpperLimit--;
                break;
                /* 温度下限 */
                case ENGINEER_MENU_TEMPERATURE_LOWER_LIMIT: 
                    if(sysParams.regs.temperatureLowerLimit > 5)
                        sysParams.regs.temperatureLowerLimit--;
                break;
                /* 制冷模式使能 */
                case ENGINEER_MENU_COOLING_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport &= ~AIR_CONDITIONER_MODE_SUPPORTED_COOLING_MASK;
                break;
                /* 制热模式使能 */
                case ENGINEER_MENU_HEATING_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport &= ~AIR_CONDITIONER_MODE_SUPPORTED_HEATING_MASK;
                break;
                /* 通风模式使能 */
                case ENGINEER_MENU_AIR_CIRCULATION_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport &= ~AIR_CONDITIONER_MODE_SUPPORTED_AIR_CIRCULATION_MASK;
                break;
                /* 除湿模式使能 */
                case ENGINEER_MENU_DEHUMIDIFICATION_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport &= ~AIR_CONDITIONER_MODE_SUPPORTED_DEHUMIDIFICATION_MASK;
                break;
                /* 温度单位 */
                case ENGINEER_MENU_TEMPERATURE_UNIT: 
                    sysParams.regs.temperatureUnit = TEMPERATURE_UNIT_CELSIUS;
                break;  
                /* 通讯地址 */
                case ENGINEER_MENU_COMMUNICATION_ADDR: 
                    if(sysParams.commAddr > 0x01)
                        sysParams.commAddr--;
                break;     
                default:
                break;
            }
        }
    }
    /* 检测到up键按下，切换菜单或调整参数 */
    if(sysParams.btn.btnUp == PRESSED)
    {
        sysParams.btn.btnUp = RELEASED;
        /* 未选中要修改的参数 */
        if((*isSelected & 0x01) == 0)   
        {
            /* 选中要修改的参数，进行参数调整 */
            if(sysParams.advancedMenu < ENGINEER_MENU_COMMUNICATION_ADDR)
            {
                sysParams.advancedMenu++;
            }
        }
        /* 选中要修改的参数，进行参数调整 */
        else    
        {
            /* 调整后参数先显示，后闪烁 */
            sysParams.isDisplayFlicker = 0x11;

            switch(sysParams.advancedMenu)
            {
                /* 温度校准 */
                case ENGINEER_MENU_TEMPERATURE_CALIBRATION: 
                    if(sysParams.regs.temperatureCalibration < 8)
                    {
                        sysParams.regs.temperatureCalibration++;
                    }
                break;
                /* 节能开关 */
                case ENGINEER_MENU_MODE_ECONOMIC:           
                    sysParams.regs.isEconomicMode = 1;
                break;
                /* 风机控制 */
                case ENGINEER_MENU_AIR_BLOWER_CONTROLLED:   
                    sysParams.regs.isAirBlowerControlled = 1;
                break;
                /* 低温保护 */
                case ENGINEER_MENU_LOW_TEMPERATURE_PROTECTED: 
                    sysParams.regs.isLowTemperatureProtected = 1;
                break;
                /* 断电记忆功能 */
                case ENGINEER_MENU_POWER_OFF_MEMORY:        
                    sysParams.regs.isPowerOffMemory = 1;
                break;
                /* 回差上限 */
                case ENGINEER_MENU_BACKLASH_UPPER_LIMIT: 
                    if(sysParams.regs.backlashUpperLimit < 6)
                        sysParams.regs.backlashUpperLimit++;
                break;
                /* 回差上限 */
                case ENGINEER_MENU_BACKLASH_LOWER_LIMIT: 
                    if(sysParams.regs.backlashLowerLimit < 0)
                        sysParams.regs.backlashLowerLimit++;
                break;
                /* 温度上限 */
                case ENGINEER_MENU_TEMPERATURE_UPPER_LIMIT: 
                    if(sysParams.regs.temperatureUpperLimit < 35)
                        sysParams.regs.temperatureUpperLimit++;
                break;
                /* 温度下限 */
                case ENGINEER_MENU_TEMPERATURE_LOWER_LIMIT: 
                    if(sysParams.regs.temperatureLowerLimit < 35)
                        sysParams.regs.temperatureLowerLimit++;
                break;
                /* 制冷模式使能 */
                case ENGINEER_MENU_COOLING_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport |= AIR_CONDITIONER_MODE_SUPPORTED_COOLING_MASK;
                break;
                /* 制热模式使能 */
                case ENGINEER_MENU_HEATING_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport |= AIR_CONDITIONER_MODE_SUPPORTED_HEATING_MASK;
                break;
                /* 通风模式使能 */
                case ENGINEER_MENU_AIR_CIRCULATION_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport |= AIR_CONDITIONER_MODE_SUPPORTED_AIR_CIRCULATION_MASK;
                break;
                /* 除湿模式使能 */
                case ENGINEER_MENU_DEHUMIDIFICATION_SUPPORTED: 
                    sysParams.regs.airConditionerModeSupport |= AIR_CONDITIONER_MODE_SUPPORTED_DEHUMIDIFICATION_MASK;
                break;
                /* 温度单位 */
                case ENGINEER_MENU_TEMPERATURE_UNIT: 
                    sysParams.regs.temperatureUnit = TEMPERATURE_UNIT_FAHRENHEIT;
                break;  
                /* 通讯地址 */
                case ENGINEER_MENU_COMMUNICATION_ADDR: 
                    if(sysParams.commAddr <= 0xFE)
                        sysParams.commAddr++;
                break;     
                default:
                break;
            }
        }
    }
}

void sys_page_advanced(u8 *isSelected)
{
    /* 工程师菜单切换至高级菜单 */
    if(sysParams.advancedMenu < ADVANCED_MENU_VERSION_INFO)    
    {
        sysParams.advancedMenu = ADVANCED_MENU_VERSION_INFO;
    }
    /* 检测到power键按下，返回系统界面 */
    if(sysParams.btn.btnPower == PRESSED)
    {
        sysParams.btn.btnPower = RELEASED;
        sysParams.presentPage = sysParams.regs.sysPage;
    }
    /* 检测到mode键按下，切换选中状态 */
    if(sysParams.btn.btnMode == PRESSED)
    {
        sysParams.btn.btnMode = RELEASED;
        /*切换选中状态*/
        *isSelected ^= 0x01;
        /* 选中参数，开始闪烁*/
        if(*isSelected)
            sysParams.isDisplayFlicker = 0x11;
        else
            sysParams.isDisplayFlicker = 0;
    }
    /* 检测到wind键按下，工程师模式无需理会 */
    if(sysParams.btn.btnWindSpeed == PRESSED)
    {
        sysParams.btn.btnWindSpeed = RELEASED;
        /* 高级模式无风速选项 */
    }
    /* 检测到down键按下，切换菜单或调整参数 */
    if(sysParams.btn.btnDown == PRESSED)
    {
        sysParams.btn.btnDown = RELEASED;
        /* 未选中要修改的参数 */
        if((*isSelected & 0x01) == 0)   
        {
            /* 切换菜单 */
            if(sysParams.advancedMenu > ADVANCED_MENU_VERSION_INFO)
            {
                sysParams.advancedMenu--;
            }
        }
        /* 选中要修改的参数，进行参数调整 */
        else      
        {
            /* 调整后参数先显示，后闪烁 */
            sysParams.isDisplayFlicker = 0x11;
            switch(sysParams.advancedMenu)
            {
                /* 版本信息 */
                case ADVANCED_MENU_VERSION_INFO: 
                    //版本信息为只读状态
                    *isSelected &= ~0x01;
                    sysParams.isDisplayFlicker = 0;
                break;
                /* 波特率 */
                case ADVANCED_MENU_BRADRATE:    
                    if(sysParams.commBradrate > MODBUS_BAUDRATE_2400)       
                    sysParams.commBradrate--;
                break;
                /* 机型使能 */
                case ADVANCED_MENU_MACHINE_SUPPORTED:   
                    switch(sysParams.regs.machineTypeSupported)
                    {
                        case MACHINE_TYPE_AIR_CONDITIONER:
                        {
                            
                        }
                        break;
                        case MACHINE_TYPE_FLOOR_HEATING:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_AIR_CONDITIONER;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        case MACHINE_TYPE_FRESH_AIR:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FLOOR_HEATING;
                            sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
                        }
                        break;
                        case MACHINE_TYPE_AIR_CONDITIONER_AND_FLOOR_HEATING:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FRESH_AIR;
                            sysParams.regs.sysPage = PAGE_FRESH_AIR;
                        }
                        break;
                        case MACHINE_TYPE_AIR_CONDITIONER_AND_FRESH_AIR:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_AIR_CONDITIONER_AND_FLOOR_HEATING;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        case MACHINE_TYPE_FLOOR_HEATING_AND_FRESH_AIR:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_AIR_CONDITIONER_AND_FRESH_AIR;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        case MACHINE_TYPE_FULL_FUNCTION:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FLOOR_HEATING_AND_FRESH_AIR;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        default:
                            break;
                    }
                break;
                /* 背光亮度 */
                case ADVANCED_MENU_LUMINANCE:   
                    if(sysParams.backligntLevel > 1)
                        sysParams.backligntLevel--;
                break;
                /* 继电器模式 */
                case ADVANCED_MENU_RELAY_MODE:   
                    if(sysParams.relayMode > RELAY_MODE_AIR_CONDITIONER)
                        sysParams.relayMode--;
                break;
                default:
                    break;
            }
        }
    }
    /* 检测到up键按下，切换菜单或调整参数 */
    if(sysParams.btn.btnUp == PRESSED)
    {
        sysParams.btn.btnUp = RELEASED;
        /* 未选中要修改的参数 */
        if((*isSelected & 0x01) == 0)   
        {
            /* 切换菜单 */
            if(sysParams.advancedMenu < ADVANCED_MENU_RELAY_MODE)
            {
                sysParams.advancedMenu++;
            }
        }
        /* 选中要修改的参数，进行参数调整 */
        else    
        {
            /* 调整后参数先显示，后闪烁 */
            sysParams.isDisplayFlicker = 0x11;
            switch(sysParams.advancedMenu)
            {
                /* 版本信息 */
                case ADVANCED_MENU_VERSION_INFO: 
                    //版本信息为只读状态
                    *isSelected &= ~0x01;
                    sysParams.isDisplayFlicker = 0;
                break;
                /* 波特率 */
                case ADVANCED_MENU_BRADRATE:    
                    if(sysParams.commBradrate < MODBUS_BAUDRATE_9600)       
                    sysParams.commBradrate++;
                break;
                /* 机型使能 */
                case ADVANCED_MENU_MACHINE_SUPPORTED:   
                    switch(sysParams.regs.machineTypeSupported)
                    {
                        case MACHINE_TYPE_AIR_CONDITIONER:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FLOOR_HEATING;
                            sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
                        }
                        break;
                        case MACHINE_TYPE_FLOOR_HEATING:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FRESH_AIR;
                            sysParams.regs.sysPage = PAGE_FRESH_AIR;
                        }
                        break;
                        case MACHINE_TYPE_FRESH_AIR:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_AIR_CONDITIONER_AND_FLOOR_HEATING;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        case MACHINE_TYPE_AIR_CONDITIONER_AND_FLOOR_HEATING:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_AIR_CONDITIONER_AND_FRESH_AIR;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        case MACHINE_TYPE_AIR_CONDITIONER_AND_FRESH_AIR:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FLOOR_HEATING_AND_FRESH_AIR;
                            sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
                        }
                        break;
                        case MACHINE_TYPE_FLOOR_HEATING_AND_FRESH_AIR:
                        {
                            sysParams.regs.machineTypeSupported = MACHINE_TYPE_FULL_FUNCTION;
                            sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                        }
                        break;
                        case MACHINE_TYPE_FULL_FUNCTION:
                        {
                            
                        }
                        break;
                        default:
                            break;
                    }
                break;
                /* 背光亮度 */
                case ADVANCED_MENU_LUMINANCE:   
                    if(sysParams.backligntLevel < 8)
                        sysParams.backligntLevel++;
                break;
                /* 继电器模式 */
                case ADVANCED_MENU_RELAY_MODE:   
                    if(sysParams.relayMode < RELAY_MODE_FRESH_AIR_FLOOR_HEATING)
                        sysParams.relayMode++;
                break;
                default:
                break;
            }
        }
    }
}

void sys_page_error(void)
{

}
void sys_func(void)
{
    /* 是否选中要修改的参数 */
    static u8 __xdata isSelected;   
    /* 关机状态下，检测组合键 */
    if((((sysParams.regs.powerStatus & POWER_AIR_CONDITIONER_MASK) == 0) && sysParams.regs.sysPage == PAGE_AIR_CONDITIONER) || \
    (((sysParams.regs.powerStatus & POWER_FLOOR_HEATING_MASK) == 0) && sysParams.regs.sysPage == PAGE_FLOOR_HEATING) || \
    (((sysParams.regs.powerStatus & POWER_FRESH_AIR_MASK) == 0) && sysParams.regs.sysPage == PAGE_FRESH_AIR))
    {
        /* 检测到up键长按6s */
        if(sysParams.btn.btnUp == LONG_PRESSED_6S)
        {
            sysParams.btn.btnUp = RELEASED;
            /* 检测到Up & down 同时长按6s,进入高级模式 */
            if(sysParams.btn.btnDown == LONG_PRESSED_6S)
            {
                sysParams.btn.btnDown = RELEASED;
                sysParams.presentPage = PAGE_ADVANCED;   
            }
            /* 检测到up键长按6s,退网 */
            else    
            {
                //暂无联网功能
            }
        }
        /* 检测到down键长按6s */
        else if(sysParams.btn.btnDown == LONG_PRESSED_6S)  
        {
            sysParams.btn.btnDown = RELEASED;
            /* 检测到down & up 同时长按6s，进入高级模式 */
            if(sysParams.btn.btnUp == LONG_PRESSED_6S)      
            {
                sysParams.btn.btnUp = RELEASED;
                sysParams.presentPage = PAGE_ADVANCED;  
            }
            /* 检测到down & mode 同时长按6s，恢复出厂设置 */
            if(sysParams.btn.btnMode == LONG_PRESSED_6S)      
            {
                sysParams.btn.btnMode = RELEASED;
                sys_params_DeInit();  
            }
        }
        /* 检测到mode键长按6s，进入工程师模式 */
        else if(sysParams.btn.btnMode == LONG_PRESSED_6S)  
        {
            sysParams.btn.btnMode = RELEASED;
            /* 检测到down & mode 同时长按6s，恢复出厂设置 */
            if(sysParams.btn.btnDown == LONG_PRESSED_6S)      
            {
                sysParams.btn.btnDown = RELEASED;
                sys_params_DeInit();  
            }
            else
            {
                sysParams.presentPage = PAGE_ENGINEER; 
            }
        }
    }
    /* 开机状态下，组合键无效 */
    else
    {
        if(sysParams.btn.btnUp == LONG_PRESSED_6S)
        {
            sysParams.btn.btnUp = RELEASED;
        }
        if(sysParams.btn.btnDown == LONG_PRESSED_6S)
        {
            sysParams.btn.btnDown = RELEASED;
        }
        if(sysParams.btn.btnMode == LONG_PRESSED_6S)
        {
            sysParams.btn.btnMode = RELEASED;
        }
    }
    /* 检测到power键长按3s，按键锁状态切换 */
    if(sysParams.btn.btnPower == LONG_PRESSED_3S)  
    {
        sysParams.btn.btnPower = RELEASED; 
        sysParams.regs.isBtnLocked ^= 1;
    }
    /* 检测到page键短按 */
    if(sysParams.btn.btnPage == PRESSED && sysParams.presentPage != PAGE_ERROR)   
    {
        sysParams.btn.btnPage = RELEASED;
        isSelected = 0;
        sysParams.isDisplayFlicker = 0;
        switch(sysParams.regs.machineTypeSupported)
        {
            case MACHINE_TYPE_AIR_CONDITIONER:  
            case MACHINE_TYPE_FLOOR_HEATING:
            case MACHINE_TYPE_FRESH_AIR:    
                /* 当一系统，无系统界面可切换 */
                break;
            
            case MACHINE_TYPE_AIR_CONDITIONER_AND_FLOOR_HEATING:
                /* 切换系统界面 */
                if(sysParams.presentPage < PAGE_ENGINEER)
                {
                    if(sysParams.regs.sysPage == PAGE_AIR_CONDITIONER)
                        sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
                    else
                        sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                }
                break;

            case MACHINE_TYPE_AIR_CONDITIONER_AND_FRESH_AIR:
                /* 切换系统界面 */
                if(sysParams.presentPage < PAGE_ENGINEER)
                {
                    if(sysParams.regs.sysPage == PAGE_AIR_CONDITIONER)
                        sysParams.regs.sysPage = PAGE_FRESH_AIR;
                    else
                        sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                }
                break;

            case MACHINE_TYPE_FLOOR_HEATING_AND_FRESH_AIR:
                /* 切换系统界面 */
                if(sysParams.presentPage < PAGE_ENGINEER)
                {
                    if(sysParams.regs.sysPage == PAGE_FLOOR_HEATING)
                        sysParams.regs.sysPage = PAGE_FRESH_AIR;
                    else
                        sysParams.regs.sysPage = PAGE_FLOOR_HEATING;
                }
                break;

            case MACHINE_TYPE_FULL_FUNCTION:
                /* 切换系统界面 */
                if(sysParams.presentPage < PAGE_ENGINEER)
                {
                    if(sysParams.regs.sysPage < PAGE_FRESH_AIR)
                        sysParams.regs.sysPage++;
                    else
                        sysParams.regs.sysPage = PAGE_AIR_CONDITIONER;
                }
                break;

            default:
                break;
        }
        /* 返回系统界面 */
        sysParams.presentPage = sysParams.regs.sysPage;
    }
    /* 界面显示 */
    switch(sysParams.presentPage)
    {
        /* 空调界面 */
        case PAGE_AIR_CONDITIONER:  
        {
            sys_page_airConditioner();
        }
        break;
        /* 地暖界面 */
        case PAGE_FLOOR_HEATING:
        {
            sys_page_floorHeating();
        }
        break;
        /* 新风界面 */
        case PAGE_FRESH_AIR:
        {
            sys_page_fleshAir();
        }
        break;
        /* 工程师界面 */
        case PAGE_ENGINEER:
        {
            sys_page_engineer(&isSelected);
        }
        break;
        /* 高级界面 */
        case PAGE_ADVANCED:
        {
            sys_page_advanced(&isSelected);
        }
        break;
        default:
            break;
    }
}

void timer0_int (void) __interrupt TIMER0_VECTOR
{
    if(COM2.RX_TimeOut > 0)
    {
        COM2.RX_TimeOut--;
        if(COM2.RX_TimeOut == 0)
        {
            COM2.B_RX_OK = 1;
        }
    }
    
    if(sysTimer.sysTimerCnt < 0xFEFFFFFF)
        sysTimer.sysTimerCnt++;
    else
        sysTimer.sysTimerCnt = 0;

    irm_sender();

    if(sysTimer.sysTimerCnt % 20 == 0)
        sysTimer.sysTimerFlag10ms = 1;
    if(sysTimer.sysTimerCnt % 40 == 0)
        sysTimer.sysTimerFlag20ms = 1;
    if(sysTimer.sysTimerCnt % 100 == 0)
        sysTimer.sysTimerFlag50ms = 1;
    if(sysTimer.sysTimerCnt % 200 == 0)
        sysTimer.sysTimerFlag100ms = 1;
    if(sysTimer.sysTimerCnt % 500 == 0)
        sysTimer.sysTimerFlag200ms = 1;
    if(sysTimer.sysTimerCnt % 1000 == 0)
        sysTimer.sysTimerFlag500ms = 1;
    if(sysTimer.sysTimerCnt % 2000 == 0)
        sysTimer.sysTimerFlag1000ms = 1;
    if(sysTimer.sysTimerCnt % 4000 == 0)
        sysTimer.sysTimerFlag2000ms = 1;
}
